/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.jm.financeiro.entity;

import br.jm.financeiro.base.eao.EaoException;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author joao
 */
@Entity
@Table(name = "proposta_etapa_desc", catalog = "salao", schema = "public")
@NamedQueries({
    @NamedQuery(name = "PropostaEtapaDesc.findAll", query = "SELECT p FROM PropostaEtapaDesc p")})
public class PropostaEtapaDesc implements Comparable<PropostaEtapaDesc>, Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "proposta_etapa_desc_id_etapa_desc_seq")
    @SequenceGenerator(name = "proposta_etapa_desc_id_etapa_desc_seq", sequenceName = "proposta_etapa_desc_id_etapa_desc_seq", initialValue = 1, allocationSize = 1)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_etapa_desc", nullable = false)
    private Integer idEtapaDesc;
    @Size(max = 100)
    @Column(name = "dsc_etapa1", length = 100)
    private String dscEtapa1;
    @Size(max = 100)
    @Column(name = "dsc_etapa2", length = 100)
    private String dscEtapa2;
    @Column(name = "num_etapa", length = 100)
    private String numEtapa;
    @Column(name = "num_etapa_compl", length = 100)
    private String numEtapaCompl;
    @Column(name = "obs_Etapa1", columnDefinition = "text")
    private String obsEtapa1;
    @Column(name = "obs_Etapa2", columnDefinition = "text")
    private String obsEtapa2;

    @LazyCollection(LazyCollectionOption.FALSE)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idEtapaDesc")
    private List<PropostaEtapaPerc> propostaEtapaPercList;

    @JoinColumn(name = "id_etapa", referencedColumnName = "id_etapa", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private PropostaEtapa idEtapa;
    
    public PropostaEtapaDesc() {
        
    }

    public PropostaEtapaDesc(Integer idEtapaDesc) {
        this.idEtapaDesc = idEtapaDesc;
    }

    public Integer getIdEtapaDesc() {
        return idEtapaDesc;
    }

    public void setIdEtapaDesc(Integer idEtapaDesc) {
        this.idEtapaDesc = idEtapaDesc;
    }

    public String getDscEtapa1() {
        return dscEtapa1;
    }

    public void setDscEtapa1(String dscEtapa1) {
        this.dscEtapa1 = dscEtapa1;
    }

    public String getDscEtapa2() {
        return dscEtapa2;
    }

    public void setDscEtapa2(String dscEtapa2) {
        this.dscEtapa2 = dscEtapa2;
    }

    public String getNumEtapa() {
        return numEtapa;
    }

    public void setNumEtapa(String numEtapa) {
        this.numEtapa = numEtapa;
    }

    public String getObsEtapa1() {
        return obsEtapa1;
    }

    public void setObsEtapa1(String obsEtapa1) {
        this.obsEtapa1 = obsEtapa1;
    }

    public String getObsEtapa2() {
        return obsEtapa2;
    }

    public void setObsEtapa2(String obsEtapa2) {
        this.obsEtapa2 = obsEtapa2;
    }

    public List<PropostaEtapaPerc> getPropostaEtapaPercList() throws EaoException {
        if (propostaEtapaPercList != null) {
            Collections.sort(propostaEtapaPercList);
        }

        return propostaEtapaPercList;
    }

    public void setPropostaEtapaPercList(List<PropostaEtapaPerc> propostaEtapaPercList) {
        this.propostaEtapaPercList = propostaEtapaPercList;
    }

    public PropostaEtapa getIdEtapa() {
        return idEtapa;
    }

    public void setIdEtapa(PropostaEtapa idEtapa) {
        this.idEtapa = idEtapa;
    }

    public String getNumEtapaCompl() {
        return numEtapaCompl;
    }

    public void setNumEtapaCompl(String numEtapaCompl) {
        this.numEtapaCompl = numEtapaCompl;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idEtapaDesc != null ? idEtapaDesc.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PropostaEtapaDesc)) {
            return false;
        }
        PropostaEtapaDesc other = (PropostaEtapaDesc) object;
        if ((this.idEtapaDesc == null && other.idEtapaDesc != null) || (this.idEtapaDesc != null && !this.idEtapaDesc.equals(other.idEtapaDesc))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.jm.financeiro.entity.PropostaEtapaDesc[ idEtapaDesc=" + idEtapaDesc + " ]";
    }

    @Override
    public int compareTo(PropostaEtapaDesc o) {
        /*
         if (this.numEtapa == null) {
         this.numEtapa = "0";
         } else if (this.numEtapa.isEmpty()) {
         this.numEtapa = "0"; 
         }
         if (o.numEtapa == null) {
         o.numEtapa = "0";
         } else if (o.numEtapa.isEmpty()) {
         o.numEtapa = "0"; 
         }
         */
        int valor = Integer.parseInt(this.numEtapa);
        int valor2 = Integer.parseInt(o.numEtapa);
        return valor - valor2;
    }
}
